package com.woniu.woniuproject.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.woniuproject.entity.Debtor_record;
import com.woniu.woniuproject.service.Debtor_recordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("debtrecord")
public class Debt_recordController {
    @Autowired
    Debtor_recordService debtorRecordService;

    @ResponseBody
    @GetMapping("/list")
    public Map<String, PageInfo> list(@RequestParam(value="currentPage",defaultValue="1")int currentPage,
                                      @RequestParam(value="pageSize",defaultValue="5")int pageSize,
                                      @RequestParam (value="startTime",defaultValue="1900-01-01")String startTime,@RequestParam (value="endTime",defaultValue="2099-12-31")String endTime) throws ParseException {
        HashMap<String, PageInfo> map = new HashMap<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date start = sdf.parse(startTime);
        Date end = sdf.parse(endTime);
        PageInfo<Debtor_record> pageInfo = debtorRecordService.selectApplyList(currentPage, pageSize, start, end);
        map.put("data", pageInfo);
        System.out.println(pageInfo);

        return map;
    }


}
